import pandas
import pathlib
import os
import tkinter.filedialog
import shutil
import uuid

# 初始的运行路径
InitRunPath = os.getcwd()

# 获取当前脚本所在的路径
CurrentPath = pathlib.Path(__file__).parent.absolute().resolve().__str__()

# 获取当前用户的桌面路径
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")

# 切换运行路径到脚本所在路径
os.chdir(CurrentPath)

# 获取Excel文件的路径
Comment_Path = tkinter.filedialog.askopenfilename(
    title="选择评价文本文件",
    initialdir=CurrentPath,
    filetypes=[("评价文本集合文件", "*.TXT")],
    multiple=False  # 启用多选功能
)

# 读取所有的文本评价
with open(file=Comment_Path, mode='r', encoding='utf-8') as file:
    comments = file.readlines()

# 去除每条评价的首尾空白字符
comments = [comment.strip() for comment in comments if comment.strip()]

# 选择输出创建路径的父级目录
OutputPath = tkinter.filedialog.askdirectory(
    title="选择输出创建路径的父级目录",
    initialdir=desktop_path
)

# 创建输出文件夹
pathlib.Path(OutputPath).joinpath("评价文本集合").mkdir(parents=True, exist_ok=True)

# 遍历所有的文本评价
for index,comment in enumerate(comments,start=1):
    print(f"评价 {index}: {comment}")
    pathlib.Path(OutputPath).joinpath("评价文本集合").joinpath(f"评价{index}").mkdir(parents=True, exist_ok=True)
    with open(file=pathlib.Path(OutputPath).
                                            joinpath("评价文本集合").
                                            joinpath(f"评价{index}").
                                            joinpath("comment.txt"),
              mode="w",
              encoding="utf-8") as f:
        f.write(comment)